package com.eusoft.demo.handle;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @authoe DevMing
 * @data 2021/8/19 19:12
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        if (metaObject.hasSetter("timeAdd")) {
            this.strictInsertFill(metaObject, "timeAdd", LocalDateTime.class, LocalDateTime.now());
        }
        if (metaObject.hasSetter("timeUpdateLast")) {
            this.strictInsertFill(metaObject, "timeUpdateLast", LocalDateTime.class, LocalDateTime.now());
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        if (metaObject.hasSetter("timeUpdateLast")) {
            this.strictUpdateFill(metaObject, "timeUpdateLast", LocalDateTime.class, LocalDateTime.now());
        }
    }
}
